import * as numeral from 'numeral';

export function asCurrency(amount) {
  return `¥ ${numeral(amount).format('0,0.00')}`;
}

export function asYuan(amount) {
  return asCurrency(numeral(amount).divide(100.0));
}

export function trimTrailingZero(amount) {
  return amount.replace(/0*?$/g, '').replace(/\.$/g, '');
}

export function asRmb(amount) {
  return numeral(amount || 0)
    .divide(100.0)
    .format('0.00');
}

export function prettyRmb(amount) {
  return trimTrailingZero(numeral(amount).divide(100.0).format('0,0.00'));
}

export function asBigRmb(amount) {
  if (amount >= 1000000) {
    // 超过1万则以万为单位
    return `${trimTrailingZero(
      numeral(amount || 0)
        .divide(1000000.0)
        .format('0.00')
    )}万`;
  }
  return trimTrailingZero(asRmb(amount)
  );
}

export function asCent(amount) {
  return asCurrency(numeral(amount).multiply(100.0));
}
